<?php
     /**************************************************************************************
     * Bookswapp is a web application which allow students to exchange their textbooks
     * It is developed by students of ITE "C. Colamonico" - Sistemi Informativi Aziendali
     * Acquaviva delle Fonti (BA) - Italy
     *
     * Bookswapp is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Affero General Public License version 3 as published by the
     * Free Software Foundation
     *
     * Bookswapp is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
     * details.
     *
     * You should have received a copy of the GNU Affero General Public License along 
     * with this program; if not, see http://www.gnu.org/licenses or write to the Free
     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     * 02110-1301 USA.
     *
     * You can contact ITE "C. Colamonico" with a mailing address at Via Colamonico, 5 
     * 70021 - Acquaviva delle Fonti (BA) Italy, or at email address bookswapp@itccolamonico.it.
     *
     * The interactive user interfaces in original and modified versions
     * of this program must display Appropriate Legal Notices, as required under
     * Section 5 of the GNU Affero General Public License version 3.
     *
     * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
     * these Appropriate Legal Notices must retain the display of the Bookswapp
     * logo and ITE "C. Colamonico" copyright notice. If the display of the logo is not reasonably
     * feasible for technical reasons, the Appropriate Legal Notices must display the words
     * "Copyright ITE C. Colamonico - http://www.itccolamonico.it - 2014. All rights reserved".
     ****************************************************************************************/
?>

<?php

/**
 * This is the model base class for the table "{{school}}".
 * DO NOT MODIFY THIS FILE! It is automatically generated by giix.
 * If any changes are necessary, you must set or override the required
 * property or method in class "School".
 *
 * Columns in table "{{school}}" available as properties of the model,
 * followed by relations of table "{{school}}" available as properties of the model.
 *
 * @property string $id_school
 * @property string $name_school
 * @property string $code_school
 * @property string $order_school
 * @property string $zip_school
 * @property string $city_school
 * @property string $district_school
 * @property string $address_school
 * @property string $phone1_school
 * @property string $fax_school
 * @property string $phone2_school
 * @property string $email1_school
 * @property string $email2_school
 * @property string $url_school
 *
 * @property mixed $bswAdmins
 * @property Classroom[] $classrooms
 */
abstract class BaseSchool extends GxActiveRecord {

	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

        /**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return '{{school}}';
	}

        /**
         * @return the active record label (the user friendly name displayed in the views)
         */
	public static function label($n = 1) {
		return Yii::t('app', 'School|Schools', $n);
	}

        /**
         *  @returns string|array The name of the representing column/s (array) for the table
         */
	public static function representingColumn() {
		return 'name_school';
	}

        /**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		return array(
			array('name_school, city_school, address_school', 'required'),
			array('name_school', 'length', 'max'=>200),
			array('code_school', 'length', 'max'=>30),
			array('order_school, district_school, email1_school, email2_school', 'length', 'max'=>45),
			array('zip_school', 'length', 'max'=>5),
			array('city_school, address_school, url_school', 'length', 'max'=>60),
			array('phone1_school, fax_school, phone2_school', 'length', 'max'=>20),
			array('code_school, order_school, zip_school, district_school, phone1_school, fax_school, phone2_school, email1_school, email2_school, url_school', 'default', 'setOnEmpty' => true, 'value' => null),
			array('id_school, name_school, code_school, order_school, zip_school, city_school, district_school, address_school, phone1_school, fax_school, phone2_school, email1_school, email2_school, url_school', 'safe', 'on'=>'search'),
		);
	}

        /**
	 * @return array relational rules.
	 */
	public function relations() {
		return array(
			'bswAdmins' => array(self::MANY_MANY, 'Admin', '{{admin_has_school}}(school_id, admin_id)'),
			'classrooms' => array(self::HAS_MANY, 'Classroom', 'school_id'),
		);
	}

        /**
	 * The pivot model is used by GxActiveRecord::saveWithRelated().
         * @return array list of pivot models for each MANY_MANY relationship. 
	 */
	public function pivotModels() {
		return array(
			'bswAdmins' => 'AdminHasSchool',
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */        
	public function attributeLabels() {
		return array(
			'id_school' => Yii::t('app', 'Id School'),
			'name_school' => Yii::t('app', 'Name School'),
			'code_school' => Yii::t('app', 'Code School'),
			'order_school' => Yii::t('app', 'Order School'),
			'zip_school' => Yii::t('app', 'Zip School'),
			'city_school' => Yii::t('app', 'City School'),
			'district_school' => Yii::t('app', 'District School'),
			'address_school' => Yii::t('app', 'Address School'),
			'phone1_school' => Yii::t('app', 'Phone1 School'),
			'fax_school' => Yii::t('app', 'Fax School'),
			'phone2_school' => Yii::t('app', 'Phone2 School'),
			'email1_school' => Yii::t('app', 'Email1 School'),
			'email2_school' => Yii::t('app', 'Email2 School'),
			'url_school' => Yii::t('app', 'Url School'),
			'bswAdmins' => null,
			'classrooms' => null,
		);
	}

        /**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search() {
		$criteria = new CDbCriteria;

		$criteria->compare('id_school', $this->id_school, true);
		$criteria->compare('name_school', $this->name_school, true);
		$criteria->compare('code_school', $this->code_school, true);
		$criteria->compare('order_school', $this->order_school, true);
		$criteria->compare('zip_school', $this->zip_school, true);
		$criteria->compare('city_school', $this->city_school, true);
		$criteria->compare('district_school', $this->district_school, true);
		$criteria->compare('address_school', $this->address_school, true);
		$criteria->compare('phone1_school', $this->phone1_school, true);
		$criteria->compare('fax_school', $this->fax_school, true);
		$criteria->compare('phone2_school', $this->phone2_school, true);
		$criteria->compare('email1_school', $this->email1_school, true);
		$criteria->compare('email2_school', $this->email2_school, true);
		$criteria->compare('url_school', $this->url_school, true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
		));
	}
}